package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import www.lagou.entity.Transaction;
import www.lagou.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

public class TransactionDao {

    // 向 transaction 插入数据
    public void insert( Transaction transaction) throws SQLException {

        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        String sql = "insert into transaction(cardid,tratype,tramoney,tradate) value(?,?,?,?)";

        Object[] param = {transaction.getCardid(),transaction.getTratype(),transaction.getTramoney(),transaction.getTradate()};

        qr.update(sql, param);
    }

    // 向 transaction 插入数据
    public void insert(Connection conn, Transaction transaction) throws SQLException {

        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        String sql = "insert into transaction(cardid,tratype,tramoney,tradate) value(?,?,?,?)";

        Object[] param = {transaction.getCardid(),transaction.getTratype(),transaction.getTramoney(),transaction.getTradate()};

        qr.update(conn,sql, param);
    }

}
